<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .isClassTodos {
            text-decoration: line-through;
            color: #999;
        }

        li {
            margin: 10px;
        }
    </style>
    <script src="./js/vue.js"></script>
</head>

<body>

    <div id="div1">
        <input type="text" v-model="newValue" @keyup.enter="insert">
        <button @click="insert">添加</button>
        <ul>

            <template v-for="(item,index) in todos">
                <li :id="item.Id" v-if="item.IsFinish == showFinish || showFinish == undefined">
                    <input type="checkbox" v-bind:checked="item.IsFinish" @click="item.IsFinish = !item.IsFinish">
                    <span v-bind:class="item.IsFinish?'finish':''">{{item.Name}}</span>
                    <span v-if="item.IsFinish">&nbsp;已完成</span>
                    <span v-else>&nbsp;未完成</span>
                    <button @click="isDelete(index)">删除</button>
                </li>
            </template>
        </ul>

        <button @click="showFinish=undefined">全部</button>
        <button @click="showFinish==true">已完成</button>
        <button @click="showFinish==false">未完成</button>
    </div>

    <script>
        let app = Vue.createApp({
            data() {
                return {
                    showFinish: undefined,
                    newValue: '',
                    todos: [
                        {
                            Id: 1,
                            Name: '抽烟',
                            IsFinish: false
                        },
                        {
                            Id: 2,
                            Name: '喝酒',
                            IsFinish: true
                        },
                        {
                            Id: 3,
                            Name: '烫头',
                            IsFinish: false
                        }
                    ]
                }
            },
            methods: {
                insert() {
                    if (!this.newValue.length) {
                        return;
                    }
                    this.todos.push({
                        Id: this.todos.length + 1,
                        Name: this.newValue,
                        IsFinish: false
                    })
                    this.newValue = '';
                },
                isDelete(index) {
                    this.todos.splice(index, 1);
                }
            }

        }).mount('#div1');

    </script>
</body>

</html>